package com.pm.service.caveatConf.impl;

import com.pm.entity.po.caveatConf.CaveatConf;
import com.pm.mapper.caveatConf.CaveatConfMapper;
import com.pm.service.caveatConf.CaveatConfService;
import com.pm.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CaveatConfServiceImpl extends BaseServiceImpl<CaveatConf> implements CaveatConfService {
    @Autowired
    CaveatConfMapper caveatConfMapper;

    @Resource
    private void setBaseMapper(CaveatConfMapper caveatConfMapper) {
        super.setBaseMapper(caveatConfMapper);
    }

    @Override
    public List<CaveatConf> getListAll(CaveatConf caveatConf) {
        return caveatConfMapper.getListAll(caveatConf);
    }

    @Override
    public Boolean canAdd(CaveatConf caveatConf) {
        // 获取最小值
        Integer minGt = caveatConfMapper.getMinGt();
        // 需要新增的最大值比当前库的最小值都小，则必定可以新增
        if (caveatConf.getLe() < minGt) {
            return true;
        } else {
            Integer countNum = caveatConfMapper.getSectionSum(caveatConf);
            if (countNum > 0) {
                return false;
            } else {
                return true;
            }
        }
    }
}


